﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Boxie
{
    public partial class frmConfigAddAlias : Form
    {
        ListView lst;

        public frmConfigAddAlias(ListView l)
        {
            InitializeComponent();
            lst = l;
            if (BoxieRegLib.GetSettingBool("General/WindowTopMost", true))
                this.TopMost = true;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtAlias.Text == "")
                return;
            if(txtIP.Text=="")
                return;
            string[] checkIP = txtIP.Text.Split('.');
            if (checkIP.GetUpperBound(0) != 3)
            {
                MessageBox.Show("Please use a valid IP address!");
                return;
            }
            for (int i = 0; i < lst.Items.Count; i++)
            {
                if (lst.Items[i].Text.ToLower() == txtAlias.Text.ToLower())
                {
                    MessageBox.Show("Alias already exists!\nPick a different name and try again.");
                    return;
                }
            }
            ListViewItem lvi = lst.Items.Add(txtAlias.Text);
            lvi.SubItems.Add(txtIP.Text);

            this.Close();
        }
    }
}
